﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Axis.BusinessObject.Research;
using Axis.Dao.Research;
using Axis.Web.Administrator.Global;
using System.Xml;
using System.Text;
using Axis.Dao.Layout;
using Axis.BusinessObject.Layout;
using Axis.BusinessObject.Core;
namespace Axis.Web.Views.Gift
{
    public class GiftUI : System.Web.UI.Page
    {
        CResearchDao cResearchDao = null;
        public GiftUI()
        {
            cResearchDao = new CResearchDao();
        }
        public string GetSliderList()
        {
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("InputValue");
            doc.AppendChild(root);
            root.SetAttribute("PageIndex", "1");
            root.SetAttribute("RowsPerPage", "999");
            string inputValue = root.OuterXml;


            return SliderListHTML(inputValue);
        }
        public IList<CGift> GetMemberGift()
        {
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("InputValue");
            doc.AppendChild(root);
            root.SetAttribute("UserID", member.ID.ToString());
            root.SetAttribute("MemberID", member.ID.ToString());
            root.SetAttribute("SecrectToken", member.SecrectToken);
            root.SetAttribute("Context", "Member");
            string inputValue = root.OuterXml;
            IList<CGift> list = cResearchDao.GetGift(inputValue);
            return list;
        }
        protected string SliderListHTML(string inputValue)
        {
            StringBuilder ret = new StringBuilder();
            CLayoutDao cLayoutDao = new CLayoutDao();
            IList<CSlideBarItem> list = cLayoutDao.GetSlideBarItem(inputValue);
            if (list != null && list.Count > 0)
            {
                foreach (CSlideBarItem gift in list)
                {
                    ret.Append(SliderHTML(gift));
                }
            }
            return ret.ToString();
        }
        protected string SliderHTML(CSlideBarItem gift)
        {
            StringBuilder ret = new StringBuilder();
            if (gift != null)
            {
                int id = gift.ID;
                string name = gift.Name;
                string desc = gift.Description;
                string image = gift.Image;
                string projectID = gift.ProjectID.ToString();
                string url = gift.Url;
                var html = SliderTemplate();
                html = html.Replace("[ID]", id.ToString());
                html = html.Replace("[Image]", image);
                html = html.Replace("[Name]", name);
                html = html.Replace("[Description]", desc);
                html = html.Replace("[ProjectID]", projectID);
                //
                if (gift.ProjectID != 0)
                {
                    var link = "../Project/Project.aspx?ProjectID=" + projectID;
                    html = html.Replace("[Link]", link);
                }
                else
                {
                    html = html.Replace("[Link]", url);
                }
                ret.Append(html);
            }
            return ret.ToString();
        }
        protected string SliderTemplate()
        {
            string output = ""
                + "<div class='jshowoff-item' GiftID='[ID]' ProjectID='[ProjectID]'>"
                    + "<img src='[Image]' class='eddie' />"
                    + "<div class='eddie-content'>"
                        + "<h2 class='gift-name'>[Name]</h2>"
                        + "<div class='gift-body'>"
                            + "<div class='gift-description'>"
                                + "<div>[Description]</div>"
                                + "<div class='gift-description-focus'></div>"
                            + "</div>"
                            + "<div class='gift-detail'>"
                                + "<a href='[Link]'>Chi tiết</a>"
                            + "</div>"
                        + "</div>"
                    + "</div>"
                + "</div>";
            return output;
        }
    }


}